package com.information.manage.basic.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.information.manage.basic.model.query.*;
import com.information.manage.basic.model.vo.StaffFindDetailVO;
import com.information.manage.basic.model.vo.StaffNameAndJobNumberVO;
import com.information.manage.basic.model.vo.StaffPageVO;
import com.information.manage.basic.common.result.Result;
import com.information.manage.basic.service.StaffService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author sy
 * @since 2021-12-29
 */
@Api(tags = "员工管理")
@RestController
@RequestMapping("/staff")
public class StaffController {

    @Resource
    private StaffService staffService;

    @PostMapping("/add")
    @ApiOperation(value = "新增员工", notes = "新增员工")
    public Result<Integer> addStaff(@RequestBody StaffAddQuery staffAddQuery, MultipartFile image) {
        return staffService.addStaff(staffAddQuery, image);
    }

    @DeleteMapping("/delete")
    @ApiOperation(value = "删除员工", notes = "删除员工")
    public Result<Boolean> deleteStaff(@RequestBody List<Integer> staffIds) {
        return Result.ok(staffService.deleteStaff(staffIds));
    }

    @GetMapping("/query/page")
    @ApiOperation(value = "分页查询员工", notes = "分页查询员工")
    public Result<Page<StaffPageVO>> queryStaffPage(StaffPageQuery staffPageQuery) {
        return staffService.queryStaffPage(staffPageQuery);
    }

    @GetMapping("/query/by/combination")
    @ApiOperation(value = "姓名或者工号查询员工", notes = "姓名或者工号查询员工")
    public Result<List<StaffNameAndJobNumberVO>> queryStaffByCombination(String combination){
        return Result.ok(staffService.queryStaffByCombination(combination));
    }

    @PutMapping("/update")
    @ApiOperation(value = "修改员工", notes = "修改员工")
    public Result<Boolean> updateStaff(@RequestBody StaffUpdateQuery staffUpdateQuery, MultipartFile image) {
        return staffService.updateStaff(staffUpdateQuery, image);
    }

    @GetMapping("/query/detail")
    @ApiOperation(value = "查询员工详情", notes = "查询员工详情")
    public Result<StaffFindDetailVO> detailStaff(Integer staffId) {
        return staffService.detailStaff(staffId);
    }

    @GetMapping("/retire")
    @ApiOperation(value = "员工退休", notes = "员工退休")
    public Result<Boolean> retireStaff(List<Integer> staffIds) {
        return Result.ok(staffService.retireStaff(staffIds));
    }

    @PostMapping("/fingerprint/input")
    @ApiOperation(value = "指纹录入", notes = "指纹录入")
    public Result<Boolean> fingerPrintInput(@RequestBody FingerprintInputQuery fingerprintInputQuery) {
        return Result.ok(staffService.fingerPrintInput(fingerprintInputQuery.getStaffId(), fingerprintInputQuery.getFingerprint()));
    }

    @GetMapping("/delete/fingerprint")
    @ApiOperation(value = "删除指纹", notes = "删除指纹")
    public Result deleteFingerprint(Integer staffId){
        staffService.deleteFingerprint(staffId);
        return Result.ok();
    }

    @GetMapping("/excel/export")
    @ApiOperation(value = "员工导出", notes = "员工导出")
    public void excelExport(HttpServletResponse response, StaffExportQuery staffExportQuery) {
        staffService.excelExport(response, staffExportQuery);
    }

    @GetMapping("/download/excel")
    @ApiOperation(value = "下载模板", notes = "下载模板")
    public void downloadExcel(HttpServletResponse response) {
        staffService.downloadExcel(response);
    }

    /**
     * 导入zip格式 员工信息存放在excel中 图片放到zip下以工号.jpg命名
     * @param response
     * @param file
     * @return
     */
    @PostMapping("/excel/import")
    @ApiOperation(value = "员工导入", notes = "员工导入")
    public Result excelImport(HttpServletResponse response, @RequestParam("file") MultipartFile file) {
        return staffService.excelImport(response, file);
    }

}
